package com.heima.demo;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.InetAddress;
import java.net.ServerSocket;
import java.net.Socket;

public class TCP1 {
    public static void main(String[] args) throws Exception {
        //创建对象
        ServerSocket ss = new ServerSocket(10000);
        //监听客户端数据
        Socket sc = ss.accept();
        //获取流对象
        InputStream is = sc.getInputStream();
        //将字节流转换为字符流
        BufferedReader bf = new BufferedReader(new InputStreamReader(is));
        //第一行数据
        String s = bf.readLine();
        //获取客户端ip
        InetAddress inetAddress = sc.getInetAddress();
        System.out.println(inetAddress.getHostAddress());
        System.out.println(s);
        //释放资源
        sc.close();
        ss.close();
    }
}
